<?php
class NewsCatalogAction extends CommonAction {
	
	public $table = "news_catalog" ; 


	/**
	 * 
	 * 新增新闻分类
	 */
	public function addNewsCatalog(){
		$model = M( "news_catalog" );	
		$data["name"] = $_REQUEST ['name'];
		
		//保存图片
		$imgName = $this->_upload();		
		$data["imageurl_small"] = "s_".$imgName ;
		$data["imageurl_big"] = "m_".$imgName ;
		
		$data["createdate"] = date('Y-m-d H:i:s',time());
		$data["statusdate"] = date('Y-m-d H:i:s',time());
		$data["status"] = $_REQUEST ['status'];		
		$this->resultHandle($model->add($data),"新增新闻分类成功！","新增新闻分类失败！");
	}
	
	public function edit(){		
		$condition['id'] = $_REQUEST['id'];		
		$this->assign( "newsCatalogVo" , $this->CommonSimplequery($condition, "news_catalog",1));
		$this->display();
	}
	
	/**
	 * 修改状态 
	 * 
	 */
	public function statusHandle(){		
		$model = D( "news_catalog" );		
		$id = $_REQUEST ['id'];		
		$condition['id'] = $id ;
		$vo = $this->CommonSimplequery($condition, "news_catalog",1);
		$data['status'];
		if($vo['status'] == 1){
			$data['status'] = 0  ;
		}else{
			$data['status'] = 1  ;
		}
   	    $this->resultHandle($model->where($condition)->save($data),"新闻分类状态修改成功！","新闻分类状态修改失败！") ;

	}
	
	/**
	 * 
	 * 修改产品分类
	 */
	public function editNewsCatalog(){
		$model = D( "news_catalog" );			
		$condition['id'] = $_REQUEST ['id'];		
		$vo = $this->CommonSimplequery($condition, "news_catalog",1);
		$data['status'];
		if($vo['status'] == 1){
			$data['status'] = 0  ;
		}else{
			$data['status'] = 1  ;
		}
		
		if( $_FILES['image']['name'] != ''){				
			$imgName = $this->_upload();
			$data["imageurl_small"] = "s_".$imgName ;
			$data["imageurl_big"] = "m_".$imgName ;
		}
		$data["statusdate"] = date('Y-m-d H:i:s',time());			
		$data['name'] = $_REQUEST ['name'];		
   	    $this->resultHandle($model->where($condition)->save($data),"新闻分类信息修改成功！","新闻分类信息修改失败！") ;
	}
}
?>